package 数组.middle;

/**
 * @author Lw中
 * @date 2021/9/16 12:02
 */
public class YiLuEr {

    // 162.寻找峰值
    public int findPeakElement(int[] nums) {
        // 方法一：循环遍历寻找到最大值（峰值），时间复杂度为O(n)
        // 方法二：使用二分查找
        int left = 0, right = nums.length - 1, res = 0;
        while (left < right) {
            int m = (left + right) / 2;
            if (nums[m] > nums[m+1]) right = m;
            else if(nums[m] <= nums[m+1]) left = m + 1;
        }
        return left;
    }

}
